using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;

namespace RTPMethods
{
	class CygwinWrapper
	{

        static void launchXserve()
        {
            Process cygwin = new Process();

            cygwin.StartInfo.FileName = "C:\\cygwin\\Cygwin.bat";
            //cygwin.StartInfo.Arguments = "--login -i ";

            cygwin.StartInfo.RedirectStandardError = true;
            cygwin.StartInfo.RedirectStandardInput = true;
            cygwin.StartInfo.RedirectStandardOutput = true;
            cygwin.StartInfo.CreateNoWindow = true;
            cygwin.StartInfo.UseShellExecute = false;
            cygwin.StartInfo.ErrorDialog = false;

            //start process!
            cygwin.Start();

            //create delegates for asynchronous calls during output/error received
            DataReceivedEventHandler errorEventHandler = new DataReceivedEventHandler(ErrorDataReceived);
            DataReceivedEventHandler outEventHandler = new DataReceivedEventHandler(OutDataReceived);

            //assign delegates
            cygwin.OutputDataReceived += outEventHandler;
            cygwin.ErrorDataReceived += errorEventHandler;

            //begin asynchronous monitoring
            cygwin.BeginErrorReadLine();
            cygwin.BeginOutputReadLine();

            //start xserve!
            cygwin.StandardInput.WriteLine("cd \"C:/Program Files (x86)/Crossbow/Moteview/xserve2/bin\"");
            cygwin.StandardInput.WriteLine("./xserve -device=com6 -xmlc -xmlport=9005");

            while (true)
            {
            }

        }
        static void ErrorDataReceived(object sender, DataReceivedEventArgs errorLine)
        {
          //  Console.WriteLine(errorLine.Data);
        }

        static void OutDataReceived(object sender, DataReceivedEventArgs outLine)
        {
           //need to find a way to convert this to a readable format
            Console.WriteLine(outLine.Data);
        }
   
    }
}



		